"""
演示RDD的flatMap成员方法的使用
功能:对RDD执行map操作,然后进行接触嵌套工作
"""

from pyspark import SparkContext,SparkConf
import os

os.environ['PYSPARK_PYTHON'] = "C:/Users/86131/AppData/Local/Programs/Python/Python39/python.exe"
conf = SparkConf().setMaster("local[*]").setAppName("test_spark")
sc = SparkContext(conf=conf)
#准备一个RDD
rdd = sc.parallelize(["itheima itcast 666", "itheima itheima itcast", "python itheima"])

#需求:将RDD数据里面的一一个单词提取出来
# rdd2 = rdd.map(lambda x: x.split(" ")) >>[['itheima', 'itcast', '666'], ['itheima', 'itheima', 'itcast'], ['python', 'itheima']]
rdd2 = rdd.flatMap(lambda x: x.split(" ")) #>>['itheima', 'itcast', '666', 'itheima', 'itheima', 'itcast', 'python', 'itheima']
print(rdd2.collect())






sc.stop()